﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using Chinaer.Model;
using System.Data.Entity.Core.Objects;

namespace Chinaer.Dao.EF
{
    /// <summary>
    /// 操作数据库上下文
    /// </summary>
    public class ChinaerContext : DbContext, IDisposable
    {

        private static ChinaerContext _chinaerContext = null;
        public ChinaerContext()
            : base("name=ContextConn")
        {
       
        }
        static ChinaerContext()
        {
            Database.SetInitializer<ChinaerContext>(null);
         //   Database.SetInitializer<ChinaerContext>(new DropCreateDatabaseAlways<ChinaerContext>());
           // Database.SetInitializer<ChinaerContext>(new CreateDatabaseIfNotExists<ChinaerContext>());
        }
        public override int SaveChanges()
        {
            return base.SaveChanges();
        }
        /// <summary>
        /// 返回一个实例化的Context实例
        /// </summary>
        /// <returns></returns>
        public static ChinaerContext GetNewInstance()
        {
            return new ChinaerContext();
        }
        private static readonly object lockObj = new object();
        public static ChinaerContext SingletonInstance
        {
            get
            {
                lock (lockObj)
                {
                    if (_chinaerContext == null)
                    {
                        _chinaerContext = new ChinaerContext();
                    }
                }
                return _chinaerContext;
            }
        }
        /// <summary>
        /// 管理员列表
        /// </summary>
        public DbSet<Model.Entities.Model_Administrator> Administrators { get; set; }
        /// <summary>
        /// 商家列表
        /// </summary>
        public DbSet<Model.Entities.Model_ShangJia> ShangJias { get; set; }
        /// <summary>
        /// 顾客列表
        /// </summary>
        public DbSet<Model.Entities.Model_Customer> Customers { get; set; }
        /// <summary>
        /// 顾客登陆日志详细信息列表
        /// </summary>
        public DbSet<Model.Entities.Model_CustomerLoginDetails> CustomerLoginDetails { get; set; }
        /// <summary>
        /// Employee登录详细信息
        /// </summary>
        public DbSet<Model.Entities.Model_EmployeeLoginDetail> EmployeeLoginDetails { get; set; }
        /// <summary>
        /// Administrator登陆i详细信息列表
        /// </summary>
        public DbSet<Model.Entities.Model_AdministratorLoginDetail> AdministratorLoginDetails { get; set; }
        /// <summary>
        /// 角色列表
        /// </summary>
        public DbSet<Model.Entities.Model_Role> Roles { get; set; }
        /// <summary>
        /// 基础信息列表
        /// </summary>
        public DbSet<Model.Entities.Model_Base_PersonInfo> PersonInfos { get; set; }
        /// <summary>
        /// 部门列表
        /// </summary>
        public DbSet<Model.Entities.Model_Department> Departments { get; set; }
        /// <summary>
        /// 员工列表  外送员也属于员工行列 只不过职位不同
        /// </summary>
        public DbSet<Model.Entities.Model_Employee> Employees { get; set; }

        /// <summary>
        /// 性别列表
        /// </summary>
        public DbSet<Model.Entities.Model_Sex> Sexs { get; set; }

        /// <summary>
        /// 店铺列表
        /// </summary>
        public DbSet<Model.Entities.Model_DianPu> DianPus { get; set; }
        /// <summary>
        /// 店铺反馈
        /// </summary>
        public DbSet<Model.Entities.Model_DianPuFeedBack> DianPuFeedBacks { get; set; }
        /// <summary>
        /// 店铺营业状态列表
        /// </summary>
        public DbSet<Model.Entities.Model_DianPuYingYeStatus> DianPuYingYeStatus { get; set; }

        /// <summary>
        /// 店铺列表
        /// </summary>
        //  public DbSet<Model.Entities.Model_Shop> Shops { get; set; }
        /// <summary>
        /// 店铺状态列表
        /// </summary>
        //  public DbSet<Model.Entities.Model_ShopStatusNew> ShopStatus { get; set; }
        /// <summary>
        /// 菜单类别列表
        /// </summary>
        public DbSet<Model.Entities.Model_MenuCategory> MenuCategories { get; set; }
        /// <summary>
        /// 子菜单类别列表
        /// </summary>
        public DbSet<Model.Entities.Model_MenuSubCategory> MenuSubCategories { get; set; }
        /// <summary>
        /// 菜色列表
        /// </summary>
        public DbSet<Model.Entities.Model_MenuDetail> MenuDetails { get; set; }
        /// <summary>
        /// 中心公告列表
        /// </summary>
        public DbSet<Model.Entities.Model_ZhongXinGongGao> ZhongXinGongGaos { get; set; }
        /// <summary>
        /// 商家端是否阅读中心公告
        /// </summary>
        public DbSet<Model.Entities.Model_ShangJiaIsReadZhongXinTongGao> ShangJiaReadZhongXinGongGaos { get; set; }
        /// <summary>
        /// 省份列表
        /// </summary>
        public DbSet<Model.Entities.Model_Province> Provinces { get; set; }
        /// <summary>
        /// 城市列表
        /// </summary>
        public DbSet<Model.Entities.Model_City> Cities { get; set; }
        /// <summary>
        /// 顾客收货地址列表
        /// </summary>
        public DbSet<Model.Entities.Model_Address> Addresses { get; set; }
        /// <summary>
        /// 员工职位列表
        /// </summary>
        public DbSet<Model.Entities.Model_EmployeePosition> EmployeePositions { get; set; }

        /// <summary>
        /// 订单列表
        /// </summary>
        public DbSet<Model.Entities.Model_DingDan> DingDans { get; set; }
        /// <summary>
        /// 订单详细信息列表
        /// </summary>
        public DbSet<Model.Entities.Model_DingDanDetail> DingDanDetails { get; set; }
        /// <summary>
        /// 订单状态列表
        /// </summary>
        public DbSet<Model.Entities.Model_DingDanStatus> DingDanStatus { get; set; }
        /// <summary>
        /// 订单进度列表
        /// </summary>
        public DbSet<Model.Entities.Model_DingDanJinDu> DingDanJinDus { get; set; }
        /// <summary>
        /// 日志列表
        /// </summary>
        public DbSet<Model.Entities.Model_Log> Logs { get; set; }
        /// <summary>
        /// 菜单明细单位表
        /// </summary>
        public DbSet<Model.Entities.Model_MenuDetailDanWei> MenuDetailDanWeis { get; set; }
        /// <summary>
        /// 菜单明细图片列表
        /// </summary>
        public DbSet<Model.Entities.Model_MenuDetailImage> MenuDetailImages { get; set; }
        /// <summary>
        /// 商家公告列表
        /// </summary>
        public DbSet<Model.Entities.Model_ShangJiaGongGao> ShangJiaGongGaos { get; set; }
        /// <summary>
        /// 商家登陆详细列表
        /// </summary>
        public DbSet<Model.Entities.Model_ShangJiaLoginDetail> ShangJiaLoginDetails { get; set; }
        /// <summary>
        /// 外送规则表
        /// </summary>
        public DbSet<Model.Entities.Model_WaiSongGuiZe> WaiSongGuiZes { get; set; }
        /// <summary>
        /// 行政区划列表
        /// </summary>
        public DbSet<Model.Entities.Model_Area> Areas { get; set; }
        /// <summary>
        /// 顾客对于产品的反馈建议列表
        /// </summary>
        public DbSet<Model.Entities.Model_ChanPinFeedBack> ChanPinFeedBacks { get; set; }
        /// <summary>
        /// 国家列表
        /// </summary>
        public DbSet<Model.Entities.Model_Country> Countries { get; set; }
        /// <summary>
        /// 顾客对于单个订单的点评
        /// </summary>
        public DbSet<Model.Entities.Model_CustomerRemark> CustomerRemarks { get; set; }
        /// <summary>
        /// 店铺营业时间段
        /// </summary>
        public DbSet<Model.Entities.Model_DianPuYingYeTime> DianPuYingYeTimes { get; set; }
        /// <summary>
        /// 地标列表
        /// </summary>
        public DbSet<Model.Entities.Model_DiBiao> DiBiaos { get; set; }
        /// <summary>
        /// 管理员操作记录表
        /// </summary>
        public DbSet<Model.Entities.Model_Administrator_CaoZuo> AdministratorCaoZuos { get; set; }
        /// <summary>
        /// Customer操作记录表
        /// </summary>
        public DbSet<Model.Entities.Model_Customer_CaoZuo> CustomerCaoZuos { get; set; }
        /// <summary>
        /// Employee操作记录表
        /// </summary>
        public DbSet<Model.Entities.Model_Employee_CaoZuo> EmployeeCaoZuos { get; set; }
        /// <summary>
        /// ShangJia操作记录表
        /// </summary>
        public DbSet<Model.Entities.Model_ShangJia_CaoZuo> ShangJiaCaoZuos { get; set; }
        /// <summary>
        /// 菜单列表
        /// </summary>
        public DbSet<Model.UI.Model_Menu> Menus { get; set; }

        /// <summary>
        /// 异常信息保存
        /// </summary>
        public DbSet<Model.Entities.Model_Exception> Exceptions { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            
            base.OnModelCreating(modelBuilder);
        }
        void IDisposable.Dispose()
        {
            base.Dispose();
        }
    }

    /// <summary>
    /// 使用事务
    /// </summary>
    //public class ChinaerContextTransaction : ObjectContext
    //{
    //    public override int SaveChanges(SaveOptions options)
    //    {
    //        return base.SaveChanges(SaveOptions.None);
    //    }
    //    public ChinaerContextTransaction()
    //        : base("name=ContextConn")
    //    {

    //    }
    //    private static ChinaerContextTransaction _instance = null;
    //    public static ChinaerContextTransaction Instance
    //    {
    //        get
    //        {
    //            if (_instance == null)
    //            {
    //                _instance = new ChinaerContextTransaction();
    //            }
    //            return _instance;
    //        }
    //    }

    //    public static ChinaerContextTransaction GetNewInstance()
    //    {
    //        return new ChinaerContextTransaction();
    //    }
    //    /// <summary>
    //    /// 管理员列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Administrator> Administrators { get; set; }
    //    /// <summary>
    //    /// 商家列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_ShangJia> ShangJias { get; set; }
    //    /// <summary>
    //    /// 顾客列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Customer> Customers { get; set; }
    //    /// <summary>
    //    /// 角色列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Role> Roles { get; set; }
    //    /// <summary>
    //    /// 基础信息列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Base_PersonInfo> PersonInfos { get; set; }
    //    /// <summary>
    //    /// 部门列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Department> Departments { get; set; }
    //    /// <summary>
    //    /// 员工列表  外送员也属于员工行列 只不过职位不同
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Employee> Employees { get; set; }
    //    /// <summary>
    //    /// 地理信息列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_EmployeePosition> Positions { get; set; }
    //    /// <summary>
    //    /// 性别列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Sex> Sexs { get; set; }
    //    /// <summary>
    //    /// 店铺列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_Shop> Shops { get; set; }
    //    /// <summary>
    //    /// 店铺状态列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_ShopStatus> ShopStatus { get; set; }
    //    /// <summary>
    //    /// 菜单类别列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_MenuCategory> MenuCategories { get; set; }
    //    /// <summary>
    //    /// 子菜单类别列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_MenuSubCategory> SubMenuCategories { get; set; }
    //    /// <summary>
    //    /// 菜色列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_MenuDetail> MenuDetails { get; set; }
    //    /// <summary>
    //    /// 中心公告列表
    //    /// </summary>
    //    public DbSet<Model.Entities.Model_ZhongXinGongGao> ZhongXinGongGaos { get; set; }




    //}
}
